// 专门存放用户信息
export default {
	namespaced: true,
	state: {
		// 收货地址
		address: uni.getStorageSync('address') || {},
		// 登录的标识
		token: uni.getStorageSync('token') || '',
		// 用户信息对象
		userInfo: uni.getStorageSync('userInfo') || {}
	},
	mutations: {
		// 退出登录的方法
		logout(state) {
			// 清除token
			state.token = ''
			uni.setStorageSync('token', '')
			// 清除 userInfo
			state.userInfo = {}
			uni.setStorageSync('userInfo', {})
			// 清除 addreess
			state.address = {}
			uni.setStorageSync('address', {})
		},
		// 保存token
		setToken(state, token) {
			state.token = token
			// 保存到本地
			uni.setStorageSync('token', token)
		},
		// 设置收货地址
		setAddress(state, address) {
			state.address = address
			// 保存到本地
			uni.setStorageSync('address', state.address)
		},
		// 保存用户信息
		setUserInfo(state, userInfo) {
			state.userInfo = userInfo
			// 保存到本地
			uni.setStorageSync('userInfo', userInfo)
		}
	},
	actions: {},
	getters: {
		// 完整收货地址
		fullAddress: function(state) {
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address
				.detailInfo
		}
	}
}
